#include <vendor/mega/hardware/common/mega_camera_enhancement/server/1.0/IWmarkServer.h>
#include <hidl/Status.h>
#include <utils/misc.h>
#include <hidl/HidlSupport.h>
#include <stdio.h>
#include <string>

using namespace std;

using ::android::hardware::hidl_string;
using ::android::sp;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::IWmarkServer;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::WmarkPicture;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::WmarkText;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::BackgroundColor;
using vendor::mega::hardware::common::mega_camera_enhancement::server::V1_0::Font;

using std::string;
using android::sp;

int sendMsg(sp<IWmarkServer> service, string text_str, int w, int h, int x, int y, int index, int enable, BackgroundColor &bgc, Font &font) {

    WmarkText text;

    text.w = w;
    text.h = h;
    text.text = text_str;
    text.locate.x = x;
    text.locate.y = y;
    text.locate.index = index;
    text.locate.enable = enable;
    text.bg = bgc;
    text.locate.faceId[0] = 2;
    text.locate.faceId[1] = 3;
    text.locate.faceId[2] = 4;
    text.locate.faceId[3] = 5;
    text.font = font;

    service->updateText(text);

    return 0;
}

int testData(sp<IWmarkServer> service) {

    static int count = 0;
    string text = "时间: " + std::to_string(count) + "-" + std::to_string(count) + "-" + std::to_string(count) + "-" + std::to_string(count);
    count +=1;
    
    if (count > 200) {
        count = 0;
    }

    BackgroundColor bgc;
    bgc.r = 47;
    bgc.g = 49;
    bgc.b = 51;
    bgc.a = 0;

    Font font;
    font.size = 16;
    font.padding_x = 40;
    font.padding_y = 0;
    sendMsg(service, text, 700, 60,200, 200, 4, 1, bgc, font);
    return 0;

} 

int main(){
    sp<IWmarkServer> service = IWmarkServer::getService();
    if (service == nullptr){
        printf("Failed to get service\n");
        return -1;
    }

    BackgroundColor bgc;
    bgc.r = 47;
    bgc.g = 49;
    bgc.b = 51;
    bgc.a = 1;

    Font font;
    font.size = 30;
    font.padding_x = 10;
    font.padding_y = 15;

    sendMsg(service, "前", 60, 60, 500, 400, 0, 1, bgc, font);
    sendMsg(service, "后", 60, 60, 1100, 400, 1, 1, bgc, font);

    sendMsg(service, "左", 60, 60, 500, 800, 2, 1, bgc, font);
    sendMsg(service, "右", 60, 60, 1100, 800, 3, 1, bgc, font);

    while (1)
    {
        sleep(1);
        testData(service);
    }
    
    printf("init.\n");
    return 0;
}
